package com.jdk.demo.fileChannel.openfile;

import java.io.File;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class Truncate {
	
	// 如果该文件已存在并且为写入访问而打开，则其长度将被截断为0.如果只为读取访问打开文件，则忽略此选项
	public static void main(String[] args) throws Exception {
		File file = new File("p.txt");
		Path path = file.toPath();
		FileChannel fileChannel = FileChannel.open(path, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
		fileChannel.close();
	}
	// 运行上述程序后，文件内容为空

}
